package com.api.gbhg.liuwenbo.utils;

import com.api.gbhg.liuwenbo.pojo.Info;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class Utils {

    /**
     * 去除info数组多余长度
     * @return
     */
    public static Info[] removeExcessLenInfo(Info[] infos){
        List<Info> list = new ArrayList<>();
        for (Info info :infos) {
            if(info != null){
                list.add(info);
            }
        }
        Info[] newInfos = new Info[list.size()];
        for (int j = 0; j < newInfos.length; j++) {
            newInfos[j] = new Info();
            if(list.get(j).getTable() != null) {
                newInfos[j].setTable(list.get(j).getTable());
            }
            if (list.get(j).getId() != null){
                newInfos[j].setId(list.get(j).getId());
            }
            if (list.get(j).getData() != null)
                newInfos[j].setData(list.get(j).getData());

            if (list.get(j).getTitle() != null)
                newInfos[j].setTitle(list.get(j).getTitle());
        }
        return newInfos;
    }

    /**
     * 去除map数组多余长度
     * @param maps
     * @return
     */
    public static Map<String,Object>[] removeExcessLen(Map<String,Object>[] maps){
        List<Map<String,Object>> list = new ArrayList<>();
        for (Map<String,Object> map: maps) {
            if(map != null){
                list.add(map);
            }
        }
        Map<String,Object>[] newMaps = new Map[list.size()];
        for (int j = 0; j < list.size(); j++) {
            newMaps[j] = new HashMap<>();
            newMaps[j].putAll(list.get(j));
        }
        return newMaps;
    }

    /**
     * 获取当前时间
     * @return
     */
    public static String getThisDate(){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String strDate = LocalDate.now().format(dateTimeFormatter);
        return strDate;
    }
}
